﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using yncTech.Common;
using yncTech.BusinessObjects;

public partial class Admin_Fin_Fin004 : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtStartDate.Value = DateTime.Now.AddMonths(-1).Date.ToString(ConstantValue.DateFormat);
            txtEndate.Value = DateTime.Now.ToString(ConstantValue.DateFormat);
            if (Session["sd"] != null)
            {
                txtStartDate.Value = Session["sd"].ToString();
            }
            if (Session["ed"] != null)
            {
                txtEndate.Value = Session["ed"].ToString();
            }
        }

    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Session["sd"] = txtStartDate.Value;
        Session["ed"] = txtEndate.Value;
    }


    protected void PageChanged(object sender, DataGridPageChangedEventArgs e)
    {
        VShippingInfoCollection shipBoxs = new VShippingInfoCollection();

        shipBoxs.Query.Where(shipBoxs.Query.CreatedDttm >= txtStartDate.Value && shipBoxs.Query.CreatedDttm <= DateTime.Parse(txtEndate.Value).AddDays(1));

        if (!LoginUserInfo.CurrentUser.IsAdmin)
        {
            shipBoxs.Query.Where(shipBoxs.Query.ToDestination == LoginUserInfo.CurrentUser.ThirdUnitID);
        }
        shipBoxs.Query.Where(shipBoxs.Query.ShippingStatus.In(new string[]{ConstantValue.ShippingStatusCode.Waiting,ConstantValue.ShippingStatusCode.Confirmed}));
        shipBoxs.Query.OrderBy(shipBoxs.Query.ShippingStatus.Ascending, shipBoxs.Query.CreatedDttm.Descending);

        pageGrid.DataSource = shipBoxs.Query.LoadDataTable();
        pageGrid.CurrentPage = e.NewPageIndex;
        pageGrid.DataBind();
    }

    protected override void OnUnload(EventArgs e)
    {
        base.OnUnload(e);
        Session.Remove("sd");
        Session.Remove("ed");

    }
}